package com.bstek.demo.dubbo.controller;

import com.bstek.demo.dubbo.domain.Result;
import com.bstek.demo.dubbo.service.IRuleEngineService;
import com.bstek.frame.model.ApiResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: hans
 * @date: 2025/7/16 21:47
 * Description:
 */
@RestController
@RequestMapping("/dubbo/client")
public class DubboConsumerController {

    @DubboReference( version = "1.0.0", group = "urule")
    private IRuleEngineService ruleEngineService;

    /**
     * 测试执行规则
     */
    @PostMapping("/execute")
    public ApiResult<Object> executeRule() {
        try {
            String ruleCode = "rule2";
            //GeneralEntity tradeInfo = new GeneralEntity("tradeInfo");
            Map<String, Object> tradeInfo = new HashMap<>();
            tradeInfo.put("a", "2024-04-01");//标准协议开始日期
            tradeInfo.put("b", "2025-03-31");//标准协议结束日期
            tradeInfo.put("c", "2024-04-18");//认领开始日期
            tradeInfo.put("d", "3000-12-31");//认领结束日期
            tradeInfo.put("e", "可用");//商户状态名称
            tradeInfo.put("f", "2025-03-27");//交易时间
            tradeInfo.put("g", "云闪付");//交易渠道
            tradeInfo.put("h", "正交易");//交易类型
            tradeInfo.put("i", "0");//微信手续费费率
            tradeInfo.put("j", "0");//翼支付费率
            tradeInfo.put("k", "存量商户");//商户标签
            tradeInfo.put("l", "50000");//商户三方月交易净额
            tradeInfo.put("m", "366863386");//增量商户三方月交易净额
            tradeInfo.put("n", "1549340607");//存量商户三方月交易净额
            tradeInfo.put("o", "QUICKPASS");//银行编码
            tradeInfo.put("p", "0");//手续费净额
            Map<String, Object> params = new HashMap<>();
            params.put("tradeInfo", tradeInfo);
            Result executeResult = ruleEngineService.executeRule(ruleCode, params);
            return ApiResult.success(executeResult);
        } catch (Exception e) {
            return ApiResult.fail(e.getMessage());
        }
    }

}
